package com.pagepub.core.tag.validator;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class Radio extends TagSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1563478931351466991L;

	/**
	 * @param args
	 */
	private String name;

	private String beanvalue;

	private String value;

	private String classname;

	public String getBeanvalue() {
		return beanvalue;
	}

	public void setBeanvalue(String beanvalue) {
		this.beanvalue = beanvalue;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public static void main(String[] args) {
		// TODO 自动生成方法存根

	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public int doStartTag() throws JspException {
		StringBuffer str = new StringBuffer();
		JspWriter out = this.pageContext.getOut();
		String tempstr = "";
		String tempclassname = "";
		if (this.getClassname() != null
				&& "".equalsIgnoreCase(this.getClassname()))
			tempclassname = "class=\"" + this.classname + "\"";
		if (this.beanvalue.equalsIgnoreCase(this.value))
			tempstr = "<input type='radio' name=\"" + this.getName()
					+ "\" value=\"" + this.getValue()
					+ "\" checked=\"checked\" " + tempclassname + " />";
		else
			tempstr = "<input type='radio' name=\"" + this.getName()
					+ "\" value=\"" + this.getValue() + "\"  " + tempclassname
					+ "/>";
		str.append(tempstr);
		try {
			out.print(str);
		} catch (IOException e) {
			// TODO 自动生成 catch 块

			e.printStackTrace();
		}

		return 1;
	}

	public String getClassname() {
		return classname;
	}

	public void setClassname(String classname) {
		this.classname = classname;
	}

}
